<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>收货地址</title>
    <link rel="stylesheet" href="__STATIC__/before/style/base.css" type="text/css">
    <link rel="stylesheet" href="__STATIC__/before/style/global.css" type="text/css">
    <link rel="stylesheet" href="__STATIC__/before/style/header.css" type="text/css">
    <link rel="stylesheet" href="__STATIC__/before/style/home.css" type="text/css">
    <link rel="stylesheet" href="__STATIC__/before/style/address.css" type="text/css">
    <link rel="stylesheet" href="__STATIC__/before/style/bottomnav.css" type="text/css">
    <link rel="stylesheet" href="__STATIC__/before/style/footer.css" type="text/css">

</head>
<body>
<!-- 顶部导航 start -->
{include file="public/topnav" /}
<!-- 顶部导航 end -->

<div style="clear:both;"></div>

<!-- 头部 start -->
<div class="header w1210 bc mt15">
    <!-- 头部上半部分 start 包括 logo、搜索、用户中心和购物车结算 -->
    {include file="public/top-header" /}
    <!-- 头部上半部分 end -->

    <div style="clear:both;"></div>

    <!-- 导航条部分 start -->
    {include file="public/nav-different" /}
    <!-- 导航条部分 end -->
</div>
<!-- 头部 end-->

<div style="clear:both;"></div>

<!-- 页面主体 start -->
<div class="main w1210 bc mt10">


    <!-- 左侧导航菜单 start -->
    {include file="public/left_menu" /}
    <!-- 左侧导航菜单 end -->

    <!-- 右侧内容区域 start -->
    <div class="content fl ml10">
        <div class="address_hd">
            <h3>收货地址薄</h3>
            <!--<div style="display: none" {$i=0}></div>-->
            {volist id='address' name='address'}
            <dl>
                <dt>{$i}.{$address->recipient} {$address->address_name} {$address->phone}</dt>
                <dd>
                    <a href="#"
                       onclick="warning('确定要删除吗？','{:url('User/addressDel',array('id'=>$address->id))}')">删除</a>
                    <a href="#" onclick="defau({$address->id})">设为默认地址</a>
                    {//:url('User/addressDefault',array('id'=>$address->id))}
                </dd>
            </dl>
            {/volist}


        </div>

        <div class="address_bd mt10">
            <h4>新增/修改收货地址</h4>
            <form action="{:url('User/saveAndUpdate')}" name="address_form">
                <ul>
                    <li>
                        <label for=""><span>*</span>收 货 人：</label>
                        <input type="text" name="recipient" class="txt" required="required"/>
                    </li>
                    <li>
                        <label for=""><span>*</span>所在地区：</label>
                        <select name="province" id="province" onchange="province1111()">
                            <option value="">请选择</option>
                            {volist name="province" id="province" }
                            <option value="{$province.id}">{$province.name}</option>
                            {/volist}
                        </select>

                        <select name="city" id="city" onchange="county111()">
                            <option value="">请选择</option>
                        </select>

                        <select name="county" id="county" required="required">
                            <option value="">请选择</option>

                        </select>
                    </li>
                    <li>
                        <label for=""><span>*</span>详细地址：</label>
                        <input type="text" name="address" class="txt address" placeholder="请从省开始写" required="required"/>
                    </li>
                    <li>
                        <label for="" ><span>*</span>手机号码：</label>
                        <input type="text" name="phone" class="txt"  id="verty111" onblur="phoneVery11()" required="required"/>
                    </li>
                    <li>
                        <label for="">&nbsp;</label>
                        <input type="checkbox" name="defult" class="check" />设为默认地址
                    </li>
                    <li>
                        <label for="">&nbsp;</label>
                        <input type="submit" name="" class="btn" value="保存"/>
                    </li>
                </ul>
            </form>
        </div>

    </div>
    <!-- 右侧内容区域 end -->
</div>
<!-- 页面主体 end-->


<div style="clear:both;"></div>

<!-- 底部导航 start -->
{include file="public/bottomnav" /}
<!-- 底部导航 end -->

<div style="clear:both;"></div>
<!-- 底部版权 start -->
<div class="footer w1210 bc mt10">
    {include file="public/footer" /}
</div>
<!-- 底部版权 end -->
<script type="text/javascript" src="__STATIC__/before/js/jquery-1.8.3.min.js"></script>

<script type="text/javascript" src="__STATIC__/layui-v2.2.5/layui/layui.js"></script>
<script type="text/javascript" src="__STATIC__/before/js/header.js"></script>
<script type="text/javascript" src="__STATIC__/before/js/home.js"></script>

<script>
    function warning(info, url) {
        if (window.confirm(info)) {
            window.location.href = url;
        }
    }

    //设置默认地址
    function defau(id) {

        $.ajax({
            url: "{:url('User/addressDefault')}",
            dateType: "json",
            type: 'post',
            data: {
                'id': id
            },
            success: function (data) {
                // console.log(data);
                layui.use('layer', function () {
                    var layer = layui.layer;

                    if (JSON.parse(data) == 1)
                        layer.msg('设置成功！');
                    else
                        layer.msg('设置失败！');
                });
            }


        })

    }

    //一级省查二级
    function province1111() {
        var obj = document.getElementById("province").value; //定位id
        $.ajax({
            url: "{:url('User/city')}",
            type: "post",
            dataType: "json",
            data: {"province": obj},
            success: function (data) {
                // console.log(data);
                document.getElementById('city').innerHTML = "";
                document.getElementById('city').innerHTML = "<option value=''>请选择</option>";
                for (var i = 0; i < data.length; i++) {

                    document.getElementById('city').innerHTML += "<option value='" + data[i]['id'] + "'>" + data[i]['name'] + "</option>";
                }
            }
        })
    }

    //二级查三级
    function county111() {
        var oCounty = document.getElementById("city").value;
        // console.log(oCounty);
        $.ajax({
            url: "{:url('county')}",
            type: 'post',
            dataType: "json",
            data: {'county': oCounty},
            success: function (county) {
                // console.log(county);

                document.getElementById('county').innerHTML = "";
                document.getElementById('county').innerHTML = "<option value=''>请选择</option>";
                for (var i = 0; i < county.length; i++) {

                    document.getElementById('county').innerHTML += "<option value='" + county[i]['id'] + "'>" + county[i]['name'] + "</option>";
                }
            }
        })
    }

    //手机正则
    function phoneVery11() {
        // console.log(1);
        var txt111 = verty111.value;
        // console.log(txt111);
        var reg=/^1[3,4,5,7,8][0-9]{9}$/;
        var boolean=txt111.match(reg);
        if(!boolean)
            layui.use('layer', function () {
                var layer = layui.layer;
                    layer.msg('请输入正确手机号！');
            });
        // console.log(boolean);
    }

</script>
</body>
</html>